package java_作业5;

public class StringToStringBuffer {
    public static void main(String[] args) {
        // 1. 定义原始字符串
        String original = "A dog is a kind of animal";

        // 2. 转换为 StringBuffer
        StringBuffer sb = new StringBuffer(original);

        // 3. 替换 "dog" 为 "cat"
        int index = sb.indexOf("dog");
        if (index != -1) {
            sb.replace(index, index + "dog".length(), "cat");
        }

        // 4. 输出结果
        System.out.println("替换后的字符串: " + sb.toString());
    }
}